var loginpath = "/sx";
$(function(){
	$(".hs_keyboard2").plugins_keyboard();
	$(".hs_keyboard").plugins_keyboard({type:"mini"});
	$(".hs_keyboard3").plugins_keyboard({type:"mini",other:"mini2"});
});
function resetImgCode(){
	document.getElementById('yanZhengMa').src=loginpath+'/front/imgcode.html?rand='+Math.random();
}
function validata(){
	var userNameId = document.getElementById("userNameId").value.trim();
	var userNameIdResult = utils_letterNumber(userNameId, "登录名", 6, 16);
	if(!userNameIdResult){
		return false;
	}
	var passWordId = document.getElementById("passWordId").value.trim();
	var passWordIdResult = utils_letterNumber(passWordId, "密码", 6, 16);
	if(!passWordIdResult){
		return false;
	}
	var yanZhengMaId = document.getElementById("yanZhengMaId").value.trim();
	var yanZhengMaIdResult = utils_letterNumber(yanZhengMaId, "验证码", 4, 5);
	if(!yanZhengMaIdResult){
		return false;
	}
	Ext.Ajax.request(
		{
			url:loginpath+"/back/cmslogin.html",
			method:"POST",
			params:{userid:userNameId,pwd:passWordId,imgcode:yanZhengMaId},
			success:function(response,option){
				var resobj = Ext.decode(response.responseText);
				if(resobj.success){
					location.href = loginpath+"/back/index.jsp";
				}else{
					if(resobj.msg=='0'){
						alert('验证码不正确!');
						resetImgCode();
						return;
					}else if(resobj.msg=='2'){
						alert('密码错误!');
						return;
					}else if(resobj.msg == '1'){
						alert('该用户不存在!');
						return;
					}else{
						alert('系统服务忙,请稍后再试!');
						return;
					}
				}
			},
			failure:function(response,option){
				alert(resobj.success);
			}
		}
	);
//	document.userLoginForm.submit();
}
function resetFun(){
	document.userLoginForm.reset();
}

$(document).ready(function() {
	//1.初始化页面焦点
	document.getElementById("userNameId").focus();
	//2.键盘事件
	var tds = $("html"); 
	tds.keydown(function(event){
		var myEvent = event || window.event; //解决不同浏览器获取事件对象的差异
			switch(myEvent.keyCode) {
				case 13://回车事件
					validata(); break;
			}
	});
});
		